#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
import xmindparser
import re
from typing import Dict, List, Any, Optional


class XMindDialogNodeParserv9:
    """XMind文件解析为dialog_node表结构的解析器"""

    def __init__(self, file_path: str, edition_mapping: Optional[List[Dict]] = None,
                 default_edition_mapping: Optional[List[Dict]] = None):
        self.file_path = file_path
        self.raw_data = None
        self.tree_data = None
        self.node_id_counter = 0
        self.flat_nodes = []

        # 学科映射
        self.subject_mapping = {
            "政治": 7, "物理": 4, "生物": 6, "历史": 8, "信息技术": 10,
            "通用技术": 11, "数学": 2, "化学": 5, "语文": 1, "英语": 3,
            "地理": 9, "美术": 12
        }

        # 教材版本映射 - 支持动态传入
        self.edition_mapping = edition_mapping if edition_mapping is not None else [
            {"nodeId": "11", "nodeName": "通用版", "subjectId": 11},
            {"nodeId": "7", "nodeName": "新人教版", "subjectId": 7},
            {"nodeId": "8", "nodeName": "新人教版", "subjectId": 8},
            {"nodeId": "5", "nodeName": "新人教版", "subjectId": 5},
            {"nodeId": "599", "nodeName": "新人教版", "subjectId": 9},
            {"nodeId": "3", "nodeName": "新人教版", "subjectId": 3},
            {"nodeId": "1", "nodeName": "新人教版", "subjectId": 1},
            {"nodeId": "6", "nodeName": "新人教版", "subjectId": 6},
            {"nodeId": "2", "nodeName": "新人教A版", "subjectId": 2},
            {"nodeId": "10", "nodeName": "浙教版2019新教材", "subjectId": 10},
            {"nodeId": "4", "nodeName": "新人教版", "subjectId": 4},
            {"nodeId": "545", "nodeName": "新鲁科版", "subjectId": 4},
            {"nodeId": "555", "nodeName": "新鲁科版", "subjectId": 5},
            {"nodeId": "601", "nodeName": "新湘教版", "subjectId": 9},
            {"nodeId": "539", "nodeName": "新外研版", "subjectId": 3},
            {"nodeId": "563", "nodeName": "新浙科版", "subjectId": 6},
            {"nodeId": "504", "nodeName": "新人教B版", "subjectId": 2},
            {"nodeId": "565", "nodeName": "新苏教版", "subjectId": 6},
            {"nodeId": "506", "nodeName": "新湘教版", "subjectId": 2},
            {"nodeId": "547", "nodeName": "新教科版", "subjectId": 4},
            {"nodeId": "557", "nodeName": "新苏教版", "subjectId": 5},
            {"nodeId": "603", "nodeName": "新中图版", "subjectId": 9},
            {"nodeId": "541", "nodeName": "新北师大版", "subjectId": 3},
            {"nodeId": "508", "nodeName": "新苏教版", "subjectId": 2},
            {"nodeId": "549", "nodeName": "新粤教版", "subjectId": 4},
            {"nodeId": "605", "nodeName": "新鲁教版", "subjectId": 9},
            {"nodeId": "543", "nodeName": "新译林版", "subjectId": 3},
            {"nodeId": "512", "nodeName": "新北师大版", "subjectId": 2}
        ]

        # 默认教材版本映射 - 支持动态传入
        self.default_edition_mapping = default_edition_mapping if default_edition_mapping is not None else [
            {"subjectId": 1, "baseEditionName": "新人教版"},
            {"subjectId": 7, "baseEditionName": "新人教版"},
            {"subjectId": 8, "baseEditionName": "新人教版"}
        ]

    def update_mappings(self, edition_mapping: Optional[List[Dict]] = None,
                        default_edition_mapping: Optional[List[Dict]] = None):
        """更新映射配置"""
        if edition_mapping is not None:
            self.edition_mapping = edition_mapping
            print(f"更新 edition_mapping，共 {len(edition_mapping)} 条记录")

        if default_edition_mapping is not None:
            self.default_edition_mapping = default_edition_mapping
            print(f"更新 default_edition_mapping，共 {len(default_edition_mapping)} 条记录")

    def get_current_mappings(self) -> Dict[str, List[Dict]]:
        """获取当前使用的映射配置"""
        return {
            "edition_mapping": self.edition_mapping,
            "default_edition_mapping": self.default_edition_mapping
        }

    def parse(self) -> Optional[List[Dict]]:
        """解析XMind文件并返回dialog_node表结构"""
        try:
            # 重置计数器
            self.node_id_counter = 0
            self.flat_nodes = []

            # 使用xmindparser读取文件
            self.raw_data = xmindparser.xmind_to_dict(self.file_path)

            # 转换为dialog_node结构
            self._convert_to_dialog_nodes()

            # 后处理：设置学科ID和教材版本
            self._post_process_nodes()

            return self.flat_nodes

        except Exception as e:
            print(f"解析XMind文件失败: {e}")
            return None

    def _generate_node_id(self) -> int:
        """生成自增的数字节点ID"""
        self.node_id_counter += 1
        return self.node_id_counter

    def _convert_to_dialog_nodes(self):
        """将xmindparser的输出转换为dialog_node结构"""
        if not self.raw_data:
            return

        for sheet_index, sheet in enumerate(self.raw_data):
            root_topic = sheet.get('topic', {})
            if root_topic:
                # 从根主题开始处理，level=0
                self._process_topic(root_topic, level=0, parent_id=0, root_id=0, option_sort=1)

    def _process_topic(self, topic: Dict, level: int, parent_id: int, root_id: int, option_sort: int = 1):
        """处理主题节点"""
        node_id = self._generate_node_id()

        # 如果是根节点，设置root_id为自己的id
        if level == 0:
            root_id = node_id

        # 解析标题和规则
        title = topic.get('title', '无标题')
        parsed_result = self._parse_title_rules(title)

        # 确定节点类型：level是偶数是问题(1)，奇数是选项(2)
        node_type = 1 if level % 2 == 0 else 2

        # 确定业务类型
        biz_type = self._determine_biz_type(title, level)

        # 确定是否是叶子节点（临时设置，会在后处理中重新计算）
        children = topic.get('topics', [])
        is_leaf = 0  # 临时设置，在_set_trigger_content_and_next_node中重新计算

        # 构建ext_info - 根据规则设置（不再包含subjectId和baseEditionId）
        ext_info = self._build_ext_info(node_type, parsed_result, parent_id, level, option_sort)

        # 初始化独立的subject_id和base_edition_id字段
        subject_id, base_edition_id = self._get_initial_subject_and_edition_ids(parent_id, level)

        # 创建节点
        dialog_node = {
            "id": node_id,
            "root_id": root_id,
            "pid": parent_id,
            "copywriting": parsed_result['copywriting'],
            "description": "",
            "node_type": node_type,
            "biz_type": biz_type,
            "answer_type": parsed_result['answer_type'],
            "leaf": is_leaf,
            "biz_code": "desk",
            "subject_id": subject_id,  # 新增独立字段
            "base_edition_id": base_edition_id,  # 新增独立字段
            "trigger_type": 1,
            "ext_info": ext_info,
            "trigger_content_id": 0,
            "trigger_content_name": "",
            "next_node_id": 0,
            "level": level,  # 临时字段，用于后处理
            "original_title": title  # 临时字段，用于后处理
        }

        self.flat_nodes.append(dialog_node)

        # 递归处理子节点
        for index, child_topic in enumerate(children):
            self._process_topic(child_topic, level + 1, node_id, root_id, index + 1)

    def _get_initial_subject_and_edition_ids(self, parent_id: int, level: int) -> tuple:
        """获取初始的subject_id和base_edition_id"""
        # 根据pid和level决定是否设置这些字段
        if parent_id != 0 and level > 2:  # pid不为0且level>2时才设置这些字段
            return 0, 0
        else:  # pid=0或level<=2时，不设置这些字段
            return 0, 0

    def _build_ext_info(self, node_type: int, parsed_result: Dict, parent_id: int, level: int,
                        option_sort: int) -> Dict:
        """构建ext_info，不再包含subjectId和baseEditionId字段"""
        ext_info = {}

        if node_type == 1:  # 问题节点
            # 只有多选时才添加maxSelectNum
            if parsed_result['answer_type'] == 2:
                ext_info["maxSelectNum"] = parsed_result.get('maxSelectNum', 0)
        else:  # 选项节点
            ext_info = {
                "optionSort": option_sort,
                "mutuallyExclusive": parsed_result.get('mutuallyExclusive', False)
            }

        return ext_info

    def _parse_title_rules(self, title: str) -> Dict:
        """解析标题中的规则"""
        result = {
            'copywriting': title,
            'answer_type': 0,
            'mutuallyExclusive': False,
            'maxSelectNum': 0
        }

        # 查找所有【】内容
        pattern = r'【([^】]+)】'
        matches = re.findall(pattern, title)

        for match in matches:
            if match == '单选':
                result['answer_type'] = 1
            elif match.startswith('多选'):
                result['answer_type'] = 2
                # 检查是否有数字限制
                num_match = re.search(r'多选，(\d+)', match)
                if num_match:
                    result['maxSelectNum'] = int(num_match.group(1))
            elif match == '互斥':
                result['mutuallyExclusive'] = True

        # 移除所有【】内容
        result['copywriting'] = re.sub(pattern, '', title).strip()

        return result

    def _determine_biz_type(self, title: str, level: int) -> int:
        """确定业务类型"""
        if level == 0 or level == 1:
            return 1
        elif '版本' in title or '版' in title:
            return 2
        else:
            return 0

    def _post_process_nodes(self):
        """后处理节点：设置学科ID和教材版本"""
        # 首先找到所有level=1的节点（学科节点）
        subject_nodes = [node for node in self.flat_nodes if node.get('level') == 1]

        # 为每个学科节点设置subject_id，并传播到子节点
        for subject_node in subject_nodes:
            subject_title = subject_node['original_title']
            # 清理标题中的标记符号
            clean_title = re.sub(r'【[^】]*】', '', subject_title).strip()
            subject_id = self.subject_mapping.get(clean_title, 0)

            if subject_id > 0:
                # 设置当前节点和所有子节点的subject_id
                self._set_subject_id_recursive(subject_node['id'], subject_id)

        # 处理教材版本（只对level>2的节点处理）
        self._process_editions()

        # 为base_edition_id为0的节点设置默认值（只对level>2的节点处理）
        self._set_default_base_edition_ids()

        # 根据base_edition_id设置baseEditionName到ext_info中
        self._set_base_edition_name_by_id()

        # 在设置好所有信息后，处理leaf、trigger_content_name和next_node_id（包括'计划'节点逻辑）
        self._set_leaf_and_next_node_before_filter()

        # 过滤掉包含'计划'的节点
        self.flat_nodes = [node for node in self.flat_nodes if '计划' not in node.get('original_title', '')]

        # 清理临时字段
        for node in self.flat_nodes:
            if 'level' in node:
                del node['level']
            if 'original_title' in node:
                del node['original_title']

    def _set_subject_id_recursive(self, node_id: int, subject_id: int):
        """递归设置学科ID - 只对level>2或有条件的节点设置"""
        # 首先设置当前节点
        for node in self.flat_nodes:
            if node['id'] == node_id:
                node['subject_id'] = subject_id
                break

        # 然后找到所有子节点并递归设置
        child_nodes = [node for node in self.flat_nodes if node['pid'] == node_id]
        for child in child_nodes:
            # 根据条件决定是否设置subject_id
            if child['pid'] != 0 and child.get('level', 0) > 2:
                child['subject_id'] = subject_id
            # 递归处理子节点的子节点
            self._set_subject_id_recursive(child['id'], subject_id)

    def _process_editions(self):
        """处理教材版本 - 只对level>2的节点处理"""
        # 找到所有包含"版"的节点，且level>2
        edition_nodes = [node for node in self.flat_nodes
                         if '版' in node.get('original_title', '') and node.get('level', 0) > 2]

        for edition_node in edition_nodes:
            edition_title = edition_node['original_title']
            # 清理标题中的标记符号
            clean_title = re.sub(r'【[^】]*】', '', edition_title).strip()
            subject_id = edition_node['subject_id']

            # 设置baseEditionName到ext_info中
            if 'baseEditionName' not in edition_node['ext_info']:
                edition_node['ext_info']['baseEditionName'] = clean_title

            # 查找匹配的base_edition_id
            base_edition_id = self._find_base_edition_id(clean_title, subject_id)
            if base_edition_id:
                edition_node['base_edition_id'] = int(base_edition_id)

            # 将版本信息传播到所有子节点
            self._set_edition_info_recursive(edition_node['id'], clean_title, base_edition_id)

    def _find_base_edition_id(self, edition_title: str, subject_id: int) -> Optional[str]:
        """查找匹配的教材版本ID"""
        for edition in self.edition_mapping:
            # 模糊匹配版本名称
            if (edition['nodeName'] == edition_title  and
                    edition['subjectId'] == subject_id):
                return edition['nodeId']
        return None

    def _fuzzy_match_edition(self, title1: str, title2: str) -> bool:
        """模糊匹配版本名称"""
        # 去掉常见的前缀后缀进行匹配
        clean_title1 = title1.replace('新', '').replace('版', '').replace('教材', '').replace('2019', '').strip()
        clean_title2 = title2.replace('新', '').replace('版', '').replace('教材', '').replace('2019', '').strip()

        return clean_title1 in clean_title2 or clean_title2 in clean_title1

    def _set_default_base_edition_ids(self):
        """为base_edition_id为0的节点设置默认值 - 只对level>2的节点处理"""
        for node in self.flat_nodes:
            # 检查节点是否需要设置默认值
            if (node['base_edition_id'] == 0 and
                node.get('level', 0) > 2 and
                node['pid'] != 0):

                subject_id = node['subject_id']

                print(f"节点ID {node['id']}: subject_id={subject_id}, base_edition_id为0，查找默认值")

                # 根据subject_id从默认映射中查找
                for default_mapping in self.default_edition_mapping:
                    if default_mapping['subjectId'] == subject_id:
                        # 查找对应的base_edition_id
                        base_edition_name = default_mapping['baseEditionName']
                        base_edition_id = self._find_base_edition_id(base_edition_name, subject_id)
                        if base_edition_id:
                            node['base_edition_id'] = int(base_edition_id)
                            # 同时设置baseEditionName到ext_info中
                            if 'baseEditionName' not in node['ext_info']:
                                node['ext_info']['baseEditionName'] = base_edition_name
                            print(f"为节点ID {node['id']} 设置默认base_edition_id: {base_edition_id}")
                        break
                else:
                    print(f"subject_id {subject_id} 不在默认映射中，保持base_edition_id为0")

    def _set_base_edition_name_by_id(self):
        """根据base_edition_id设置baseEditionName到ext_info中"""
        for node in self.flat_nodes:
            # 检查节点是否有base_edition_id且不为0
            base_edition_id = node.get('base_edition_id', 0)
            if base_edition_id != 0:
                # 根据base_edition_id从映射中查找对应的nodeName
                base_edition_id_str = str(base_edition_id)
                for edition in self.edition_mapping:
                    if edition['nodeId'] == base_edition_id_str:
                        if 'baseEditionName' not in node['ext_info']:
                            node['ext_info']['baseEditionName'] = edition['nodeName']
                        print(
                            f"节点ID {node['id']}: 根据base_edition_id {base_edition_id} 设置baseEditionName为: {edition['nodeName']}")
                        break
                else:
                    print(f"节点ID {node['id']}: 未找到base_edition_id {base_edition_id} 对应的版本名称")

    def _set_leaf_and_next_node_before_filter(self):
        """在过滤'计划'节点之前设置leaf、trigger_content_name和next_node_id"""
        for node in self.flat_nodes:
            # 找到当前节点的所有子节点（包括'计划'节点）
            child_nodes = [child for child in self.flat_nodes if child['pid'] == node['id']]

            # 判断leaf：如果子节点个数为1且包含'计划'关键字，则leaf=1，否则leaf=0
            if len(child_nodes) == 1 and '计划' in child_nodes[0].get('original_title', ''):
                node['leaf'] = 1
                node['next_node_id'] = 0  # 计划节点会被过滤掉，所以设置为0

                # 设置trigger_content_name：只有leaf=1时才设置
                child_node = child_nodes[0]

                # 获取baseEditionName（现在在ext_info中）
                base_edition_name = node['ext_info'].get('baseEditionName', '')

                # 如果baseEditionName为空，根据subject_id从默认映射获取
                if not base_edition_name:
                    subject_id = node.get('subject_id', 0)
                    for default_mapping in self.default_edition_mapping:
                        if default_mapping['subjectId'] == subject_id:
                            base_edition_name = default_mapping['baseEditionName']
                            # 同时更新节点的baseEditionName到ext_info中
                            node['ext_info']['baseEditionName'] = base_edition_name
                            break

                child_title = child_node['copywriting']

                print(
                    f"节点ID {node['id']} (leaf=1): subject_id={node.get('subject_id', 0)}, baseEditionName='{base_edition_name}', childTitle='{child_title}'")

                # 设置trigger_content_name：baseEditionName + "-" + 子节点title
                if base_edition_name:
                    node['trigger_content_name'] = f"{base_edition_name}-{child_title}"
                    print(f"设置trigger_content_name: {node['trigger_content_name']}")
                else:
                    node['trigger_content_name'] = child_title
                    print(f"baseEditionName为空，直接使用子节点title: {node['trigger_content_name']}")
            else:
                # 其他情况设置leaf=0，并设置next_node_id，不设置trigger_content_name
                node['leaf'] = 0
                node['trigger_content_name'] = ""  # leaf=0时，trigger_content_name为空

                # 设置next_node_id为第一个子节点的ID
                if child_nodes:
                    # 过滤掉包含'计划'的子节点
                    non_plan_children = [child for child in child_nodes if
                                         '计划' not in child.get('original_title', '')]
                    if non_plan_children:
                        node['next_node_id'] = non_plan_children[0]['id']
                        print(f"节点ID {node['id']} (leaf=0): 设置next_node_id为子节点ID: {non_plan_children[0]['id']}")
                    else:
                        node['next_node_id'] = 0
                        print(f"节点ID {node['id']} (leaf=0): 所有子节点都是计划节点，设置next_node_id为0")
                else:
                    node['next_node_id'] = 0
                    print(f"节点ID {node['id']} (leaf=0): 没有子节点，设置next_node_id为0")

    def _set_edition_info_recursive(self, parent_id: int, edition_name: str, base_edition_id: Optional[str]):
        """递归设置教材版本信息"""
        # 找到所有子节点
        child_nodes = [node for node in self.flat_nodes if node['pid'] == parent_id]

        for child in child_nodes:
            # 设置baseEditionName到ext_info中
            if 'baseEditionName' not in child['ext_info']:
                child['ext_info']['baseEditionName'] = edition_name
            # 设置base_edition_id字段
            if base_edition_id:
                child['base_edition_id'] = int(base_edition_id)

            # 递归处理子节点的子节点
            self._set_edition_info_recursive(child['id'], edition_name, base_edition_id)

    def generate_sql_insert(self, nodes: List[Dict]) -> str:
        """生成SQL插入语句"""
        if not nodes:
            return ""

        sql_parts = []
        sql_parts.append("INSERT INTO `dialog_node` (")
        sql_parts.append("  `id`, `root_id`, `pid`, `copywriting`, `description`, `node_type`, ")
        sql_parts.append("  `biz_type`, `answer_type`, `leaf`, `biz_code`, `subject_id`, `base_edition_id`, ")
        sql_parts.append("  `trigger_type`, `ext_info`, `trigger_content_id`, `trigger_content_name`, `next_node_id`")
        sql_parts.append(") VALUES")

        value_parts = []
        for node in nodes:
            ext_info_json = json.dumps(node['ext_info'], ensure_ascii=False)
            # 转义单引号
            copywriting = node['copywriting'].replace("'", "''")
            trigger_content_name = node['trigger_content_name'].replace("'", "''")

            value_part = f"({node['id']}, {node['root_id']}, {node['pid']}, " \
                         f"'{copywriting}', '{node['description']}', {node['node_type']}, " \
                         f"{node['biz_type']}, {node['answer_type']}, {node['leaf']}, " \
                         f"'{node['biz_code']}', {node['subject_id']}, {node['base_edition_id']}, " \
                         f"{node['trigger_type']}, '{ext_info_json}', {node['trigger_content_id']}, " \
                         f"'{trigger_content_name}', {node['next_node_id']})"
            value_parts.append(value_part)

        sql_parts.append(",\n".join(value_parts))
        sql_parts.append(";")

        return "\n".join(sql_parts)

    def save_to_json(self, output_path: str, nodes: List[Dict]) -> bool:
        """保存为JSON文件"""
        try:
            with open(output_path, 'w', encoding='utf-8') as f:
                json.dump(nodes, f, ensure_ascii=False, indent=2)
            print(f"已保存到: {output_path}")
            return True
        except Exception as e:
            print(f"保存文件失败: {e}")
            return False

    def save_to_sql(self, output_path: str, nodes: List[Dict]) -> bool:
        """保存为SQL文件"""
        try:
            sql_content = self.generate_sql_insert(nodes)
            with open(output_path, 'w', encoding='utf-8') as f:
                f.write(sql_content)
            print(f"已保存SQL到: {output_path}")
            return True
        except Exception as e:
            print(f"保存SQL文件失败: {e}")
            return False

    def print_nodes(self, nodes: List[Dict]):
        """打印节点信息"""
        for node in nodes:
            level = node.get('level', 0) if 'level' in node else 0
            indent = "  " * level
            print(f"{indent}ID: {node['id']}, PID: {node['pid']}, Level: {level}, "
                  f"类型: {node['node_type']}, 标题: {node['copywriting']}")
            print(f"{indent}  subject_id: {node['subject_id']}, base_edition_id: {node['base_edition_id']}")
            if node['ext_info']:
                print(f"{indent}  扩展信息: {node['ext_info']}")

    def print_original_xmind_structure(self):
        """打印原始XMind文件的JSON结构"""
        if not self.raw_data:
            print("没有原始数据可显示")
            return

        print("📄 原始XMind文件JSON结构:")
        print("=" * 60)
        print(json.dumps(self.raw_data, ensure_ascii=False, indent=2))
        print("=" * 60)

    def save_original_xmind_to_json(self, output_path: str) -> bool:
        """保存原始XMind结构为JSON文件"""
        try:
            if not self.raw_data:
                print("没有原始数据可保存")
                return False

            with open(output_path, 'w', encoding='utf-8') as f:
                json.dump(self.raw_data, f, ensure_ascii=False, indent=2)
            print(f"原始XMind结构已保存到: {output_path}")
            return True
        except Exception as e:
            print(f"保存原始XMind结构失败: {e}")
            return False


# 使用示例
def main():
    """主函数 - 使用示例"""
    # 替换为你的XMind文件路径
    file_path = "D:\\project_file\\诊断式学习\\全部.xmind"

    # 自定义教材版本映射
    dev_custom_edition_mapping = [
        {
            "nodeId": "102",
            "treeId": "3",
            "nodeName": "人教A版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "20599",
            "treeId": "10",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "9158",
            "treeId": "6",
            "nodeName": "treeId6-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9121",
            "treeId": "4",
            "nodeName": "treeId4-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "101",
            "treeId": "2",
            "nodeName": "（陈超添加）层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20005",
            "treeId": "6",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "107",
            "treeId": "8",
            "nodeName": "人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "20003",
            "treeId": "4",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20002",
            "treeId": "3",
            "nodeName": "新人教A版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "110",
            "treeId": "11",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 10
        },
        {
            "nodeId": "106",
            "treeId": "7",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "20008",
            "treeId": "9",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20010",
            "treeId": "11",
            "nodeName": "浙教版2019新教材",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 10
        },
        {
            "nodeId": "20007",
            "treeId": "8",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "9510",
            "treeId": "10",
            "nodeName": "G教1更1他1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "111",
            "treeId": "12",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 11
        },
        {
            "nodeId": "20001",
            "treeId": "2",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "9341",
            "treeId": "9",
            "nodeName": "treeId9-层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "11560",
            "treeId": "192",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 4
        },
        {
            "nodeId": "20011",
            "treeId": "12",
            "nodeName": "通用版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 11
        },
        {
            "nodeId": "20006",
            "treeId": "7",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "9466",
            "treeId": "9",
            "nodeName": "测试超过数目9",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20563",
            "treeId": "7",
            "nodeName": "新浙科版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "20601",
            "treeId": "10",
            "nodeName": "新湘教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "9109",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点2改编111",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9122",
            "treeId": "4",
            "nodeName": "treeId4-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "9094",
            "treeId": "2",
            "nodeName": "（西瓜添加）层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20555",
            "treeId": "6",
            "nodeName": "新鲁科版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9190",
            "treeId": "8",
            "nodeName": "treeId8-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "20539",
            "treeId": "4",
            "nodeName": "新外研版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20504",
            "treeId": "3",
            "nodeName": "新人教B版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9168",
            "treeId": "7",
            "nodeName": "treeId7-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "9541",
            "treeId": "10",
            "nodeName": "教22",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "9097",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "20565",
            "treeId": "7",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "10931",
            "treeId": "9",
            "nodeName": "测试一级节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20603",
            "treeId": "10",
            "nodeName": "新中图版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "20557",
            "treeId": "6",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9193",
            "treeId": "8",
            "nodeName": "treeId8-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "20541",
            "treeId": "4",
            "nodeName": "新北师大版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20506",
            "treeId": "3",
            "nodeName": "新湘教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9169",
            "treeId": "7",
            "nodeName": "treeId7-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "10596",
            "treeId": "2",
            "nodeName": "(小峰)层级1-1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "10912",
            "treeId": "9",
            "nodeName": "一级节点新增测试",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20605",
            "treeId": "10",
            "nodeName": "新鲁教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "10020",
            "treeId": "2",
            "nodeName": "（创业添加）",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11029",
            "treeId": "8",
            "nodeName": "小峰政治1级",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "20543",
            "treeId": "4",
            "nodeName": "新译林版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20508",
            "treeId": "3",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "20512",
            "treeId": "3",
            "nodeName": "新北师大版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9116",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "10936",
            "treeId": "9",
            "nodeName": "小峰1级",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "10172",
            "treeId": "2",
            "nodeName": "巴顿添加",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "9491",
            "treeId": "2",
            "nodeName": "（凯利添加）层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11030",
            "treeId": "9",
            "nodeName": "小峰1级2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "10184",
            "treeId": "2",
            "nodeName": "测试节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11151",
            "treeId": "2",
            "nodeName": "张伟伟测试2",
            "isShow": 1,
            "imageUrl": "https://test-si.ewt360.com/resources/school-admin/uploads/2024/10/31/8b79fd74-c91b-45e3-9b43-5d9cb8452853.png",
            "subjectId": 1
        },
        {
            "nodeId": "11418",
            "treeId": "2",
            "nodeName": "byt教材版本0919",
            "isShow": 1,
            "imageUrl": "https://test-si.ewt360.com/resources/school-admin/uploads/2024/10/31/8b79fd74-c91b-45e3-9b43-5d9cb8452853.png",
            "subjectId": 1
        },
        {
            "nodeId": "11467",
            "treeId": "2",
            "nodeName": "人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11526",
            "treeId": "2",
            "nodeName": "有教材版本无书本节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11528",
            "treeId": "2",
            "nodeName": "有教材有书本无章节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11534",
            "treeId": "2",
            "nodeName": "有教材有书本有章节,章节资源为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11540",
            "treeId": "2",
            "nodeName": "有教材有书本有章有节,节点资源为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        }
    ]


    test_custom_edition_mapping=[
        {
            "nodeId": "20008",
            "treeId": "9",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20010",
            "treeId": "11",
            "nodeName": "浙教版2019新教材",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 10
        },
        {
            "nodeId": "20007",
            "treeId": "8",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "9510",
            "treeId": "10",
            "nodeName": "G教1更1他1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "111",
            "treeId": "12",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 11
        },
        {
            "nodeId": "20006",
            "treeId": "7",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "9341",
            "treeId": "9",
            "nodeName": "treeId9-层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "36127",
            "treeId": "192",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 4
        },
        {
            "nodeId": "20011",
            "treeId": "12",
            "nodeName": "通用版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 11
        },
        {
            "nodeId": "102",
            "treeId": "3",
            "nodeName": "人教A版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "20599",
            "treeId": "10",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "9158",
            "treeId": "6",
            "nodeName": "treeId6-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "20005",
            "treeId": "6",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9121",
            "treeId": "4",
            "nodeName": "treeId4-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "107",
            "treeId": "8",
            "nodeName": "人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "101",
            "treeId": "2",
            "nodeName": "（陈超添加）层级1-节点11",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20003",
            "treeId": "4",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "106",
            "treeId": "7",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "20002",
            "treeId": "3",
            "nodeName": "新人教A版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "110",
            "treeId": "11",
            "nodeName": "待编辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 10
        },
        {
            "nodeId": "9168",
            "treeId": "7",
            "nodeName": "treeId7-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "20504",
            "treeId": "3",
            "nodeName": "新人教B版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9541",
            "treeId": "10",
            "nodeName": "教22",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "20001",
            "treeId": "2",
            "nodeName": "新人教版",
            "isShow": 1,
            "imageUrl": "https://cdn.ewt360.com/resources/school-admin/uploads/2025/5/26/1504ef3f-44bf-4eed-b86b-98bff9fe7ba1",
            "subjectId": 1
        },
        {
            "nodeId": "20563",
            "treeId": "7",
            "nodeName": "新浙科版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "9466",
            "treeId": "9",
            "nodeName": "测试超过数目9",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20601",
            "treeId": "10",
            "nodeName": "新湘教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "20555",
            "treeId": "6",
            "nodeName": "新鲁科版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9109",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点2改编111",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9122",
            "treeId": "4",
            "nodeName": "treeId4-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "9190",
            "treeId": "8",
            "nodeName": "treeId8-层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "9094",
            "treeId": "2",
            "nodeName": "（西瓜添加）层级1-节点2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20539",
            "treeId": "4",
            "nodeName": "新外研版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20541",
            "treeId": "4",
            "nodeName": "新北师大版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "9169",
            "treeId": "7",
            "nodeName": "treeId7-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "20506",
            "treeId": "3",
            "nodeName": "新湘教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "10596",
            "treeId": "2",
            "nodeName": "(小峰)层级1-1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20565",
            "treeId": "7",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 6
        },
        {
            "nodeId": "9097",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "10931",
            "treeId": "9",
            "nodeName": "测试一级节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20603",
            "treeId": "10",
            "nodeName": "新中图版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "20557",
            "treeId": "6",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 5
        },
        {
            "nodeId": "9193",
            "treeId": "8",
            "nodeName": "treeId8-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "11029",
            "treeId": "8",
            "nodeName": "小峰政治1级",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 7
        },
        {
            "nodeId": "10020",
            "treeId": "2",
            "nodeName": "（创业添加）",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20543",
            "treeId": "4",
            "nodeName": "新译林版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 3
        },
        {
            "nodeId": "20508",
            "treeId": "3",
            "nodeName": "新苏教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "10912",
            "treeId": "9",
            "nodeName": "一级节点新增测试",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "20605",
            "treeId": "10",
            "nodeName": "新鲁教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 9
        },
        {
            "nodeId": "10172",
            "treeId": "2",
            "nodeName": "巴顿添加",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "20512",
            "treeId": "3",
            "nodeName": "新北师大版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "9116",
            "treeId": "3",
            "nodeName": "treeId3-层级1-节点3",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 2
        },
        {
            "nodeId": "10936",
            "treeId": "9",
            "nodeName": "小峰1级",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "11030",
            "treeId": "9",
            "nodeName": "小峰1级2",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 8
        },
        {
            "nodeId": "9491",
            "treeId": "2",
            "nodeName": "（凯利添加）层级1-节点1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "10184",
            "treeId": "2",
            "nodeName": "测试节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11151",
            "treeId": "2",
            "nodeName": "张伟伟测试2",
            "isShow": 1,
            "imageUrl": "https://test-si.ewt360.com/resources/school-admin/uploads/2024/10/31/8b79fd74-c91b-45e3-9b43-5d9cb8452853.png",
            "subjectId": 1
        },
        {
            "nodeId": "11418",
            "treeId": "2",
            "nodeName": "byt教材版本0919测试byt教材版本0919测试byt教材版本0919测试",
            "isShow": 1,
            "imageUrl": "https://test-si.ewt360.com/resources/school-admin/uploads/2024/10/31/8b79fd74-c91b-45e3-9b43-5d9cb8452853.png",
            "subjectId": 1
        },
        {
            "nodeId": "11467",
            "treeId": "2",
            "nodeName": "人教版",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11526",
            "treeId": "2",
            "nodeName": "有教材版本无书本节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11528",
            "treeId": "2",
            "nodeName": "有教材有书本无章节点",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11534",
            "treeId": "2",
            "nodeName": "有教材有书本有章节,章节资源为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "11540",
            "treeId": "2",
            "nodeName": "有教材有书本有章有节,节点资源为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36048",
            "treeId": "2",
            "nodeName": "教材版本是自尊会员",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36008",
            "treeId": "2",
            "nodeName": "书本层级以下测试自尊会员",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36010",
            "treeId": "2",
            "nodeName": "书本层级以下测试节点隐藏逻辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36058",
            "treeId": "2",
            "nodeName": "教材版本测试节点隐藏逻辑",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36070",
            "treeId": "2",
            "nodeName": "自尊会员引起的书本层级为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36088",
            "treeId": "2",
            "nodeName": "隐藏节点引起的书本层级为空",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        },
        {
            "nodeId": "36131",
            "treeId": "2",
            "nodeName": "空教材版本1",
            "isShow": 1,
            "imageUrl": "",
            "subjectId": 1
        }
    ]

    # 自定义默认教材版本映射
    dev_custom_default_edition_mapping = []
    # 可以根据需要添加默认映射
    # dev_custom_default_edition_mapping = [
    #     {"subjectId": 1, "baseEditionName": "新人教版"},
    #     {"subjectId": 7, "baseEditionName": "新人教版"},
    #     {"subjectId": 8, "baseEditionName": "新人教版"},
    #     {"subjectId": 2, "baseEditionName": "新人教A版"}
    # ]

    # 创建解析器 - 方法1：初始化时传入参数
    parser = XMindDialogNodeParserv9(
        file_path,
        edition_mapping=test_custom_edition_mapping,
        default_edition_mapping=dev_custom_default_edition_mapping
    )

    # 创建解析器 - 方法2：使用默认参数后动态更新
    # parser = XMindDialogNodeParserv9(file_path)
    # parser.update_mappings(
    #     edition_mapping=custom_edition_mapping,
    #     default_edition_mapping=custom_default_edition_mapping
    # )

    # 查看当前使用的映射配置
    current_mappings = parser.get_current_mappings()
    print("当前使用的映射配置:")
    print(f"edition_mapping 数量: {len(current_mappings['edition_mapping'])}")
    print(f"default_edition_mapping 数量: {len(current_mappings['default_edition_mapping'])}")

    # 解析文件
    dialog_nodes = parser.parse()

    if dialog_nodes:
        print("✅ XMind文件解析成功！")
        print(f"共生成 {len(dialog_nodes)} 个节点")
        print("=" * 50)

        # 打印原始XMind文件的JSON结构
        print("📄 原始XMind文件结构:")
        parser.print_original_xmind_structure()

        # 保存原始XMind结构为JSON文件
        parser.save_original_xmind_to_json("original_xmind_structure_v15_test.json")

        print("\n" + "=" * 50)

        # 打印节点信息
        print("📊 解析后的节点结构:")
        parser.print_nodes(dialog_nodes)

        # 保存为JSON文件
        parser.save_to_json("dialog_nodes_v15_test.json", dialog_nodes)

        # 保存为SQL文件
        parser.save_to_sql("dialog_nodes_v15_test.sql", dialog_nodes)

        print("\n" + "=" * 50)
        print("🔍 前3个节点的详细信息:")
        for i, node in enumerate(dialog_nodes[:3]):
            print(f"\n节点 {i + 1}:")
            print(json.dumps(node, ensure_ascii=False, indent=2))

        print("\n" + "=" * 50)
        print("📁 文件保存摘要:")
        print("  ✓ original_xmind_structure_v15.json - 原始XMind结构")
        print("  ✓ dialog_nodes_v15.json - 解析后的节点数据")
        print("  ✓ dialog_nodes_v15.sql - SQL插入语句")

    else:
        print("❌ XMind文件解析失败")


if __name__ == "__main__":
    main()